/*
** Define the commands that the controller understands
*/
enum VEXCommandCode
{
        ConfigurationSetCmd = 0x00,

        MotorsSetAllCmd = 0x01,
        GetAllInputCmd = 0x02,
        SetAllPortsCmd = 0x03,

        EncoderPresetCmd = 0x04,

};

// Maximum size of a data block
#define MAX_DATA_BLOCK_SIZE   64

// Number of interrupts on the controller
#define NUM_INTERUPTS         6

// Number of IO ports on the controller
#define NUM_IO_PORTS          16

extern unsigned long MasterTicCount;

// Buffer to hold the IO port associated with an ultrasonic sensor
extern char ultrasonicIOPort[NUM_INTERUPTS];

// Buffer to hold ultrasonic and encoder measurements
extern long interruptValues[NUM_INTERUPTS];

// Buffer to hold ADC values
extern short adcValues[NUM_IO_PORTS];

// Number of ADC channels
extern char numAdc;

// IO control
extern char ioControl0;
extern char ioControl1;

// Bitmask of which interrupts are actually ultrasonic sensors
extern char sonarMask;

extern void MyHandle_New_Ping();
extern void MyStartUltrasonic(unsigned char ucInterruptNum, unsigned char ucOutputNum);
extern void MyStopUltrasonic(void);
extern int MyUltrasonicReady(void);
extern unsigned char MyGetUltrasonic(void);

// Bitmask of which interrupts are actually encoders
extern char encoderMask;

// Encoder support
extern void Handle_Encoder_Interrupt(unsigned char intHit);
extern void StartEncoder(unsigned char ucEncNum);
extern void PresetEncoder(unsigned char ucEncNum, unsigned long lValue);
extern unsigned long GetEncoder(unsigned char ucEncNum);
extern void StopEncoder(unsigned char ucEncNum);

// Setup the Interrupt handler
#define TIMER_INT_0  -1
void SetupInterruptHandler(unsigned char intNum, void (*handler)(unsigned char));

// Setup Digital output
extern void SetupDigitalOutput(unsigned char ucNum);

// Routines to call if there is a Bluetooth connection event
extern void CommunicationsTimeout(void);
extern void CommunicationsDisconnect(void);
extern void CommunicationsConnect(void);

// Helper routines for sending results back to the PC via Bluetooth
extern void SetResultByte(int offset, char byte);
extern void SetResultShort(int offset, short value);
extern void SetResultLong(int offset, long value);

// Set the configuration of the controller
extern void SetConfiguration(char *buff);

// Set all of the motors
extern void SetAllMotors(char *buff);

// Get the input values
void GetAllInput(char *buff);

// Set the output values
void SetAllPorts(char *buff);

// Preset the encoder
void EncoderPreset(char *buff);

// Command processor
extern void ProcessCommand(void);

// Processing loop
extern void MSRSInitialize(void);
